﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using University.Workshop.Model;
using System.IO;
using University.Workshop.Business;

namespace University.Workshop.WebApp
{
    public partial class ReviewOffer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Offer offer=new Offer();
            Product product = new Product();
            if (!User.Identity.IsAuthenticated)
                FormsAuthentication.RedirectToLoginPage();
            if (Session["offer"] != null)
                offer = Session["offer"] as Offer;
            product = offer.RelatedProduct;
            if (Directory.Exists(Server.MapPath("~/Thumbnails/") + product.ProductId + "/"))
            {
                DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/Thumbnails/") + product.ProductId + "/");
                FileInfo[] currentImages = dir.GetFiles();
                string thumbUrl = "~/Thumbnails/" + product.ProductId + "/";
                foreach (FileInfo fi in currentImages)
                {
                    if (String.IsNullOrEmpty(ProductImage.ImageUrl))
                    {
                        ProductImage.ImageUrl = thumbUrl + fi.Name;
                    }
                }
            }
            else
            {
                ProductImage.ImageUrl = "~/Thumbnails/NoImage/noimage.jpg";
            }
            ProductName.Text = product.Name;
            ProductPrice.Text = product.Price.ToString();
            Currency1.Text = product.Currency;
            OfferPrice.Text = offer.OfferPrice.ToString();
            Currency.Text = product.Currency;
            if (!String.IsNullOrEmpty(offer.Message))
                Message.Text = "Your message to the seller: " + offer.Message;
            else
                Message.Text = "Your message to the seller: --";
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            Response.Redirect("OfferSuccess.aspx");
        }
    }
}